//
//  ZhuangCheMainGoodCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/4/12.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "ZhuangCheMainGoodCell.h"

@interface ZhuangCheMainGoodCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *NOTitleLab;
@property (nonatomic, strong) UILabel *NOLab;
@property (nonatomic, strong) UIButton *clickBtn;
@property (nonatomic, strong) UILabel *nameTitleLab;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *packageTitleLab;
@property (nonatomic, strong) UILabel *packageLab;
@property (nonatomic, strong) UILabel *weightTitleLab;
@property (nonatomic, strong) UILabel *weightLab;
@property (nonatomic, strong) UILabel *countTitleLab;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UILabel *tiJiTitleLab;
@property (nonatomic, strong) UILabel *tiJiLab;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *z_countTitleLab;
@property (nonatomic, strong) UILabel *z_countLab;
@property (nonatomic, strong) UILabel *z_countChartLab;
@property (nonatomic, strong) UILabel *z_allCountLab;
@property (nonatomic, strong) UILabel *z_pieceTitleLab;
@property (nonatomic, strong) UILabel *z_pieceLab;
@property (nonatomic, strong) UILabel *z_pieceChartLab;
@property (nonatomic, strong) UILabel *z_allPieceLab;

@end

@implementation ZhuangCheMainGoodCell

+ (instancetype)ZhuangCheMainGoodCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"ZhuangCheMainGoodCell";
    ZhuangCheMainGoodCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ZhuangCheMainGoodCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.bgView];
        
        self.NOTitleLab = [UILabel new];
        self.NOTitleLab.textColor = HexColor(0x585974);
        self.NOTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.NOTitleLab];
        
        self.NOLab = [UILabel new];
        self.NOLab.textColor = Color_ThemeColor;
        self.NOLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.NOLab];
        
        self.clickBtn = [UIButton new];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.clickBtn];
        
        self.nameTitleLab = [UILabel new];
        self.nameTitleLab.textColor = HexColor(0x585974);
        self.nameTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.nameTitleLab];
        
        self.nameLab = [UILabel new];
        self.nameLab.textColor = HexColor(0x2B2C44);
        self.nameLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.nameLab];
        
        self.packageTitleLab = [UILabel new];
        self.packageTitleLab.textColor = HexColor(0x585974);
        self.packageTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.packageTitleLab];
        
        self.packageLab = [UILabel new];
        self.packageLab.textColor = HexColor(0x2B2C44);
        self.packageLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.packageLab];
        
        self.weightTitleLab = [UILabel new];
        self.weightTitleLab.textColor = HexColor(0x585974);
        self.weightTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.weightTitleLab];
        
        self.weightLab = [UILabel new];
        self.weightLab.textColor = HexColor(0x2B2C44);
        self.weightLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.weightLab];
        
        self.countTitleLab = [UILabel new];
        self.countTitleLab.textColor = HexColor(0x585974);
        self.countTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.countTitleLab];
        
        self.countLab = [UILabel new];
        self.countLab.textColor = HexColor(0x2B2C44);
        self.countLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.countLab];
        
        self.tiJiTitleLab = [UILabel new];
        self.tiJiTitleLab.textColor = HexColor(0x585974);
        self.tiJiTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.tiJiTitleLab];
        
        self.tiJiLab = [UILabel new];
        self.tiJiLab.textColor = HexColor(0x2B2C44);
        self.tiJiLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.tiJiLab];
        
        self.line = [UILabel new];
        self.line.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.line];
        
        self.z_countTitleLab = [UILabel new];
        self.z_countTitleLab.textColor = HexColor(0x585974);
        self.z_countTitleLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.z_countTitleLab];
        
        self.z_countLab = [UILabel new];
        self.z_countLab.textColor = HexColor(0x4AD879);
        self.z_countLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.z_countLab];
        
        self.z_countChartLab = [UILabel new];
        self.z_countChartLab.textColor = HexColor(0xDBDCE6);
        self.z_countChartLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.z_countChartLab];
        
        self.z_allCountLab = [UILabel new];
        self.z_allCountLab.textColor = HexColor(0x2B2C44);
        self.z_allCountLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.z_allCountLab];
        
        self.z_pieceTitleLab = [UILabel new];
        self.z_pieceTitleLab.textColor = HexColor(0x585974);
        self.z_pieceTitleLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.z_pieceTitleLab];
        
        self.z_pieceLab = [UILabel new];
        self.z_pieceLab.textColor = HexColor(0x4AD879);
        self.z_pieceLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.z_pieceLab];
        
        self.z_pieceChartLab = [UILabel new];
        self.z_pieceChartLab.textColor = HexColor(0xDBDCE6);
        self.z_pieceChartLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.z_pieceChartLab];
        
        self.z_allPieceLab = [UILabel new];
        self.z_allPieceLab.textColor = HexColor(0x2B2C44);
        self.z_allPieceLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.z_allPieceLab];
    }
    return self;
}

-(void)setGoodModel:(ZhuangCheMainGoodModel *)goodModel {
    _goodModel = goodModel;
    [self configUI];
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 0;
    self.bgView.nim_width = ScreenW - 30;
    
    self.NOTitleLab.text = @"货物编号：";
    [self.NOTitleLab sizeToFit];
    self.NOTitleLab.nim_left = 15;
    self.NOTitleLab.nim_top = 15;
    
    self.NOLab.text = self.goodModel.pro_num;
    [self.NOLab sizeToFit];
    self.NOLab.nim_left = self.NOTitleLab.nim_right;
    self.NOLab.nim_centerY = self.NOTitleLab.nim_centerY;
    
    self.clickBtn.nim_width = 20;
    self.clickBtn.nim_height = 20;
    self.clickBtn.nim_left = self.bgView.nim_width - 15 - self.clickBtn.nim_width;
    self.clickBtn.nim_centerY = self.NOTitleLab.nim_centerY;
    
    self.nameTitleLab.text = @"货物名称：";
    [self.nameTitleLab sizeToFit];
    self.nameTitleLab.nim_left = 15;
    self.nameTitleLab.nim_top = 5 + self.NOTitleLab.nim_bottom;
    
    self.nameLab.text = self.goodModel.name;
    [self.nameLab sizeToFit];
    self.nameLab.nim_left = self.nameTitleLab.nim_right;
    self.nameLab.nim_centerY = self.nameTitleLab.nim_centerY;
    
    if (self.goodModel.isOpen) {
        [self.clickBtn setImage:[UIImage imageNamed:@"icon_upper"] forState:0];
        
        self.packageTitleLab.text = @"包装名称：";
        [self.packageTitleLab sizeToFit];
        self.packageTitleLab.nim_left = self.nameTitleLab.nim_left;
        self.packageTitleLab.nim_top = self.nameTitleLab.nim_bottom + 5;
        
        self.packageLab.text = self.goodModel.pk_name;
        self.packageLab.nim_left = self.packageTitleLab.nim_right;
        self.packageLab.nim_top = self.packageTitleLab.nim_top;
        self.packageLab.nim_width = self.bgView.nim_width * 0.5 - self.packageLab.nim_left;
        self.packageLab.nim_height = self.packageTitleLab.nim_height;
        
        self.weightTitleLab.text = @"重量(kg)：";
        [self.weightTitleLab sizeToFit];
        self.weightTitleLab.nim_left = self.bgView.nim_width * 0.5;
        self.weightTitleLab.nim_top = self.nameTitleLab.nim_bottom + 5;
        
        self.weightLab.text = self.goodModel.weight;
        self.weightLab.nim_left = self.weightTitleLab.nim_right;
        self.weightLab.nim_top = self.weightTitleLab.nim_top;
        self.weightLab.nim_width = self.bgView.nim_width - 15 - self.weightLab.nim_left;
        self.weightLab.nim_height = self.weightTitleLab.nim_height;
        
        self.countTitleLab.text = @"收容数：";
        [self.countTitleLab sizeToFit];
        self.countTitleLab.nim_left = self.nameTitleLab.nim_left;
        self.countTitleLab.nim_top = self.packageTitleLab.nim_bottom + 5;
        
        self.countLab.text = self.goodModel.accept_num;
        self.countLab.nim_left = self.countTitleLab.nim_right;
        self.countLab.nim_top = self.countTitleLab.nim_top;
        self.countLab.nim_width = self.bgView.nim_width * 0.5 - self.countLab.nim_left;
        self.countLab.nim_height = self.countTitleLab.nim_height;
        
        self.tiJiTitleLab.text = @"体积(m³)：";
        [self.tiJiTitleLab sizeToFit];
        self.tiJiTitleLab.nim_left = self.bgView.nim_width * 0.5;
        self.tiJiTitleLab.nim_top = self.packageTitleLab.nim_bottom + 5;
        
        self.tiJiLab.text = self.goodModel.volume;
        self.tiJiLab.nim_left = self.tiJiTitleLab.nim_right;
        self.tiJiLab.nim_top = self.tiJiTitleLab.nim_top;
        self.tiJiLab.nim_width = self.bgView.nim_width - 15 - self.tiJiLab.nim_left;
        self.tiJiLab.nim_height = self.tiJiTitleLab.nim_height;
        
        self.line.frame = CGRectMake(10, self.countTitleLab.nim_bottom + 10, self.bgView.nim_width - 20, 1);
    }else {
        [self.clickBtn setImage:[UIImage imageNamed:@"icon_lower"] forState:0];
        self.packageTitleLab.frame = CGRectZero;
        self.packageLab.frame = CGRectZero;
        self.weightTitleLab.frame = CGRectZero;
        self.weightLab.frame = CGRectZero;
        self.countTitleLab.frame = CGRectZero;
        self.countLab.frame = CGRectZero;
        self.tiJiTitleLab.frame = CGRectZero;
        self.tiJiLab.frame = CGRectZero;
        
        self.line.frame = CGRectMake(10, self.nameTitleLab.nim_bottom + 10, self.bgView.nim_width - 20, 1);
    }
    
    self.z_countTitleLab.text = @"货物数量";
    [self.z_countTitleLab sizeToFit];
    self.z_countTitleLab.nim_left = 15;
    self.z_countTitleLab.nim_top = self.line.nim_bottom + 10;
    
    self.z_allCountLab.text = [NSString stringWithFormat:@"%d",self.goodModel.num];
    [self.z_allCountLab sizeToFit];
    self.z_allCountLab.nim_left = self.bgView.nim_width - 15 - self.z_allCountLab.nim_width;
    self.z_allCountLab.nim_centerY = self.z_countTitleLab.nim_centerY;
    
    self.z_countChartLab.text = @"/";
    [self.z_countChartLab sizeToFit];
    self.z_countChartLab.nim_left = self.z_allCountLab.nim_left - 10 - self.z_countChartLab.nim_width;
    self.z_countChartLab.nim_centerY = self.z_countTitleLab.nim_centerY;
    
    self.z_countLab.text = [NSString stringWithFormat:@"%d",self.goodModel.z_count];
    [self.z_countLab sizeToFit];
    self.z_countLab.nim_left = self.z_countChartLab.nim_left - 10 - self.z_countLab.nim_width;
    self.z_countLab.nim_centerY = self.z_countTitleLab.nim_centerY;
    if (self.goodModel.z_count == self.goodModel.num) {
        self.z_countLab.textColor = HexColor(0x4AD879);
    }else {
        self.z_countLab.textColor = HexColor(0xF35959);
    }
    
    self.z_pieceTitleLab.text = @"件数";
    [self.z_pieceTitleLab sizeToFit];
    self.z_pieceTitleLab.nim_left = 15;
    self.z_pieceTitleLab.nim_top = self.z_countTitleLab.nim_bottom + 10;
    
    self.z_allPieceLab.text = [NSString stringWithFormat:@"%d",self.goodModel.pnum];
    [self.z_allPieceLab sizeToFit];
    self.z_allPieceLab.nim_left = self.bgView.nim_width - 15 - self.z_allPieceLab.nim_width;
    self.z_allPieceLab.nim_centerY = self.z_pieceTitleLab.nim_centerY;
    
    self.z_pieceChartLab.text = @"/";
    [self.z_pieceChartLab sizeToFit];
    self.z_pieceChartLab.nim_left = self.z_allPieceLab.nim_left - 10 - self.z_pieceChartLab.nim_width;
    self.z_pieceChartLab.nim_centerY = self.z_pieceTitleLab.nim_centerY;
    
    self.z_pieceLab.text = [NSString stringWithFormat:@"%d",self.goodModel.z_piece];
    [self.z_pieceLab sizeToFit];
    self.z_pieceLab.nim_left = self.z_pieceChartLab.nim_left - 10 - self.z_pieceLab.nim_width;
    self.z_pieceLab.nim_centerY = self.z_pieceTitleLab.nim_centerY;
    if (self.goodModel.z_piece == self.goodModel.pnum) {
        self.z_pieceLab.textColor = HexColor(0x4AD879);
    }else {
        self.z_pieceLab.textColor = HexColor(0xF35959);
    }
    
    self.bgView.nim_height = self.z_pieceTitleLab.nim_bottom + 15;
    self.bgView.layer.cornerRadius = 6;
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
